package com.wkb.threadPoll.jdk5.instance;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**  
 * @author wkb 
 * @version 创建时间：2013-6-21 上午10:32:42  
 * 类说明  固定线程池的例子
 */
public class FixedPoolInstance {

	//创建一个内部内线程用于后面测试
	class MyThread extends Thread{
		
		public MyThread(String name) {
			
			/**
			*@version 创建时间：2013-6-21 上午10:36:04
			*/
			super(name);
			this.setName(name);
		}

		@SuppressWarnings("static-access")
		public void run(){
			
			System.out.println(this.getName() + "----执行开始");
			System.out.println(this.getId() + "----执行开始");
			System.out.println(Thread.currentThread().getName() + "----执行开始");
			System.out.println(this.getClass() + "----执行开始");
			System.out.println(Thread.currentThread().getClass() + "----执行开始");
			try {
//				Thread.currentThread().sleep(2000);
				this.sleep(5000);
			} catch (InterruptedException e) {
				e.printStackTrace();
				System.out.println(Thread.currentThread().getName() + "---睡觉失败，抛出异常！");
			}	
			System.out.println(Thread.currentThread().getName() + "----执行完成");
			
		}
		
	}
	
	public static void main(String[] args) {
		
		System.out.println(Thread.currentThread().getId());
		System.out.println(Thread.currentThread().getName());
		FixedPoolInstance fixedPoolInstance = new FixedPoolInstance();
		Thread t1 = fixedPoolInstance.new MyThread("我是t1");
		Thread t2 = fixedPoolInstance.new MyThread("我是t2");
		Thread t3 = fixedPoolInstance.new MyThread("我是t3");
		Thread t4 = fixedPoolInstance.new MyThread("我是t4");
		Thread t5 = fixedPoolInstance.new MyThread("我是t5");
		ExecutorService executorService = Executors.newFixedThreadPool(2);
		executorService.execute(t1);
		executorService.execute(t2);
//		t1.start();
		executorService.execute(t3);
//		executorService.execute(t4);
//		executorService.execute(t5);
		executorService.shutdown();
//		System.out.println("33ddd");
//		Thread tt = new Thread("rrr");
//		System.out.println(tt.getName());
	}
	
}
